﻿// zxMetaSchemaDialog.cpp: 实现文件
//

#include "stdafx.h"
#include "zxMetaSchemaDialog.h"
#include "afxdialogex.h"

#include "resource.h"

#include "MetaFieldGroupTreeView.h"

// CMetaSchemaDialog 对话框

IMPLEMENT_DYNAMIC(CMetaSchemaDialog, CDialogEx)

CMetaSchemaDialog::CMetaSchemaDialog(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_META_SCHEMA, pParent)
{
	m_pFrameWnd = NULL;
}

CMetaSchemaDialog::~CMetaSchemaDialog()
{
}

void CMetaSchemaDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CMetaSchemaDialog, CDialogEx)
	ON_WM_SIZE()
END_MESSAGE_MAP()


// CMetaSchemaDialog 消息处理程序


BOOL CMetaSchemaDialog::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	CRect rect;
	GetClientRect(&rect);

	CString strMyClass = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW,
		::LoadCursor(NULL, IDC_ARROW),
		(HBRUSH)::GetStockObject(WHITE_BRUSH),
		::LoadIcon(NULL, IDI_APPLICATION));

	m_pFrameWnd = new CFrameWnd();
	m_pFrameWnd->Create(strMyClass, _T(""), WS_CHILD, CRect(0, 0, 100, 100), this);
	m_pFrameWnd->MoveWindow(0, 0, 500, 400);
	m_pFrameWnd->ShowWindow(SW_SHOW);
	
	CCreateContext ctxList, ctxForm;
	ctxForm.m_pNewViewClass = RUNTIME_CLASS(CMetaFieldGroupTreeView);
	ctxForm.m_pCurrentDoc = NULL;
	ctxForm.m_pNewDocTemplate = NULL;
	ctxForm.m_pLastView = NULL;
	ctxForm.m_pCurrentFrame = NULL;

	ctxList.m_pNewViewClass = RUNTIME_CLASS(CListView);
	ctxList.m_pCurrentDoc = NULL;
	ctxList.m_pNewDocTemplate = NULL;
	ctxList.m_pLastView = NULL;
	ctxList.m_pCurrentFrame = NULL;

	m_wndSplitter.CreateStatic(m_pFrameWnd, 1, 2);
	m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CMetaFieldGroupTreeView), CSize(rect.Width() * 1 / 3, rect.Height()), &ctxForm);
	m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CListView), CSize(rect.Width() * 2 / 3, rect.Height()), &ctxList);

	AdjustLayout();

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CMetaSchemaDialog::OnSize(UINT nType, int cx, int cy)
{
	CDialogEx::OnSize(nType, cx, cy);

	// TODO: 在此处添加消息处理程序代码
	AdjustLayout();
}

void CMetaSchemaDialog::AdjustLayout()
{
	int margin = GetSystemMetrics(SM_CXFRAME);

	if (m_pFrameWnd)
	{
		CRect wndRect;
		GetWindowRect(&wndRect);
		ScreenToClient(wndRect);

		int margin = abs(wndRect.left);

		wndRect.left = margin;
		wndRect.top = 0;//nHeight;
		wndRect.right -= (2 * margin);
		wndRect.bottom -= (2 * margin);
		m_pFrameWnd->MoveWindow(wndRect);
	}
}